<?php
// +----------------------------------------------------------------------
// | 幕小铺
// +----------------------------------------------------------------------
// | 版权所有 2016~2020 幕小铺科技（大连）有限公司
// +----------------------------------------------------------------------
// | 2020/03/14
// +----------------------------------------------------------------------

namespace app\user_center\model\user;

use think\Model;

/**
 * 用户隐私设置 模型
 * @package app\user_center\model
 */
class UcMemberPrivacy extends Model
{
    // 设置当前模型对应的完整数据表名称
    protected $table = 'xm_uc_member_privacy';
    
    /**
     * 添加数据
     * @param int $uid 用户id
     * @author jason wang <120907037@qq.com>
     * @return array
     */
    public function addData($uid, $fans_follow_auth){
        $data['uid']                        = $uid;
        $data['fans_follow_auth']                = $fans_follow_auth;
        $res = $this -> isUpdate(false) ->data($data, true) -> save();
        if($res){
            return array_out(200, 'success');
        }else{
            return array_out(-1001, 'error');
        }
    }

    /**
     * 更新 隐私设置
     * @param int $uid 用户id
     * @author jason wang <120907037@qq.com>
     * @return array
     */
    public function updateDataByUid($uid, $fans_follow_auth){
        //查询这个用户是否存在
        $map = [];
        $map['uid'] = $uid;
        if(!$this->where($map)->find()){
            $this -> addData($uid, $fans_follow_auth);
        }

        $data = [];
        if($fans_follow_auth >= 0) $data['fans_follow_auth']                     = $fans_follow_auth;
        $map = [];
        $map['uid'] = $uid;
        $res = $this -> save($data, $map);
        if($res){
            return array_out(200, 'success');
        }else{
            return array_out(-1001, 'error');
        }
    }
}
